﻿using System;
using System.IO;
using Test30.Core;
using Test30.Engine;

namespace Test30.Data
{
    public static class Macros
    {
        public static DropMacroCollection<Item> LoadItemDrops(string dirPath, Content content)
        {
            var parser = new ItemDropParser(content);
            return LoadDrops(dirPath, parser);
        }
        public static DropMacroCollection<T> LoadDrops<T>(string dirPath, DropParser<T> parser)
        {
            DropMacroCollection<T> collection = new DropMacroCollection<T>();

            // load them
            foreach (string filePath in Directory.GetFiles(dirPath, "*.txt"))
            {
                Console.WriteLine(filePath);
                foreach (PropertyBag macroProp in PropertyBag.FromFile(filePath))
                {
                    IDrop<T> drop = parser.ParseMacro(macroProp, collection);
                    collection.Add(macroProp.Name, drop);
                }
            }

            Console.WriteLine("Loaded " + collection.Count + " drop macros");

            return collection;
        }
    }

}
